package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.NetworkSalesmanSettlementClientCollect;
import com.ruoyi.logistic.domain.NetworkSalesmanSettlementClientDetail;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.domain.vo.NetworkSalesmanSettlementClientCollectVo;
import com.ruoyi.logistic.domain.vo.NetworkSalesmanSettlementClientDetailVo;
import com.ruoyi.logistic.service.NetworkSalesmanSettlementClientDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/salesmanSettlementClient")
@RestController
@Api(tags = "网点财务_代业务员对客户结算")
public class NetworkSalesmanSettlementClientDetailController {
    @Autowired
    private NetworkSalesmanSettlementClientDetailService networkSalesmanSettlementClientDetailService;

    @ApiOperation("显示全部")
    @GetMapping("/selectAll")
    public R selectAll(PageDate pageDate){
        List<NetworkSalesmanSettlementClientDetail> networkBillDetailList = networkSalesmanSettlementClientDetailService.selectAll(pageDate);
        if (networkBillDetailList == null || networkBillDetailList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(networkBillDetailList));
        }
    }
    @ApiOperation("添加")
    @PostMapping("/insert")
    public R insert(@RequestBody NetworkSalesmanSettlementClientDetail salesmanSettlementClientDetail){
        Boolean isAdd = networkSalesmanSettlementClientDetailService.insert(salesmanSettlementClientDetail);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @ApiOperation("修改")
    @PostMapping("/update")
    public R update(@RequestBody NetworkSalesmanSettlementClientDetail salesmanSettlementClientDetail){
        Boolean isUpdate = networkSalesmanSettlementClientDetailService.update(salesmanSettlementClientDetail);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("删除")
    @PostMapping("/deleteById")
    public R deleteById(Integer id){
        Boolean isDelete = networkSalesmanSettlementClientDetailService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @ApiOperation("搜索")
    @PostMapping("/search")
    public R search(@RequestBody NetworkSalesmanSettlementClientDetailVo vo){
        if (vo.getStartTime() == null || vo.getEndTime() == null){
            return R.fail("请输入开始时间和结束时间！");
        }
        List<NetworkSalesmanSettlementClientDetail> detailList = networkSalesmanSettlementClientDetailService.search(vo);
        if (detailList == null || detailList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(detailList));
        }
    }
    @ApiOperation("汇总")
    @PostMapping("/collect")
    public R collect(@RequestBody NetworkSalesmanSettlementClientCollectVo vo){
        if (vo.getStartTime() == null || vo.getEndTime() == null || vo.getCollectType() == null){
            return R.fail("请输入开始时间和结束时间以及汇总维度！");
        }
        List<NetworkSalesmanSettlementClientCollect> list = networkSalesmanSettlementClientDetailService.collect(vo);
        if (list == null || list.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(list));
        }
    }

}
